<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title data-i18n="resources.title_themeUnique"></title>
    <style type="text/css">
        .editPane {
            position: absolute;
            right: 60px;
            top: 50px;
            text-align: center;
            background: #FFF;
            z-index: 1000;
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_themeUnique"></h5>
    </div>
    <div class='panel-body' id='params'>
        <p></p>
        <div align='right' class='button-group'>
            <input type='button' id='btn1' class='btn btn-primary' data-i18n="[value]resources.btn_addThemeLayer" onclick="addThemeUnique()"/>
            <input type='button' id='btn2' class='btn btn-primary' data-i18n="[value]resources.text_input_value_clear" onclick="removeTheme()"/>
        </div>
    </div>
</div>
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script type="text/javascript">
    var map, baseLayer, themeLayer,
        host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090",
        url = host + "/iserver/services/map-china400/rest/maps/China";

    map = new SuperMap.Map("map", {
        controls: [
            new SuperMap.Control.LayerSwitcher(),
            new SuperMap.Control.ScaleLine(),
            new SuperMap.Control.Zoom(),
            new SuperMap.Control.Navigation({
                dragPanOptions: {
                    enableKinetic: true
                }
            })]
    });
    baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("China400", url, {
        transparent: true,
        cacheEnabled: true
    }, {maxResolution: "auto"});
    baseLayer.events.on({"layerInitialized": addLayer});

    function addLayer() {
        map.addLayer(baseLayer);
        map.setCenter(new SuperMap.LonLat(10080677, 4591416), 4);
        map.allOverlays = true;
    }
    function addThemeUnique() {
        removeTheme();
        var themeService = new SuperMap.REST.ThemeService(url, {
            eventListeners: {
                "processCompleted": themeCompleted,
                "processFailed": themeFailed
            }
        });
        var style1, style2, style3, style4, style5, style6;
        style1 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(248, 203, 249),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style2 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(196, 255, 189),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style3 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(255, 173, 173),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style4 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(255, 239, 168),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style5 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(173, 209, 255),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });
        style6 = new SuperMap.REST.ServerStyle({
            fillForeColor: new SuperMap.REST.ServerColor(132, 164, 232),
            lineColor: new SuperMap.REST.ServerColor(0, 0, 0),
            lineWidth: 0.1
        });


        var themeUniqueIteme1 = new SuperMap.REST.ThemeUniqueItem({
                unique: "黑龙江省",
                style: style1
            }),
            themeUniqueIteme2 = new SuperMap.REST.ThemeUniqueItem({
                unique: "湖北省",
                style: style2
            }),
            themeUniqueIteme3 = new SuperMap.REST.ThemeUniqueItem({
                unique: "吉林省",
                style: style3
            }),
            themeUniqueIteme4 = new SuperMap.REST.ThemeUniqueItem({
                unique: "内蒙古自治区",
                style: style4
            }),
            themeUniqueIteme5 = new SuperMap.REST.ThemeUniqueItem({
                unique: "青海省",
                style: style5
            }),
            themeUniqueIteme6 = new SuperMap.REST.ThemeUniqueItem({
                unique: "新疆维吾尔自治区",
                style: style6
            }),
            themeUniqueIteme7 = new SuperMap.REST.ThemeUniqueItem({
                unique: "云南省",
                style: style1
            }),
            themeUniqueIteme8 = new SuperMap.REST.ThemeUniqueItem({
                unique: "四川省",
                style: style4
            }),
            themeUniqueIteme9 = new SuperMap.REST.ThemeUniqueItem({
                unique: "贵州省",
                style: style3
            }),
            themeUniqueIteme10 = new SuperMap.REST.ThemeUniqueItem({
                unique: "甘肃省",
                style: style3
            }),
            themeUniqueIteme11 = new SuperMap.REST.ThemeUniqueItem({
                unique: "宁夏回族自治区",
                style: style5
            }),
            themeUniqueIteme12 = new SuperMap.REST.ThemeUniqueItem({
                unique: "重庆市",
                style: style6
            }),
            themeUniqueIteme13 = new SuperMap.REST.ThemeUniqueItem({
                unique: "山东省",
                style: style1
            }),
            themeUniqueIteme14 = new SuperMap.REST.ThemeUniqueItem({
                unique: "安徽省",
                style: style2
            }),
            themeUniqueIteme15 = new SuperMap.REST.ThemeUniqueItem({
                unique: "江西省",
                style: style3
            }),
            themeUniqueIteme16 = new SuperMap.REST.ThemeUniqueItem({
                unique: "浙江省",
                style: style4
            }),
            themeUniqueIteme17 = new SuperMap.REST.ThemeUniqueItem({
                unique: "台湾省",
                style: style2
            }),
            themeUniqueIteme18 = new SuperMap.REST.ThemeUniqueItem({
                unique: "江苏省",
                style: style6
            }),
            themeUniqueIteme19 = new SuperMap.REST.ThemeUniqueItem({
                unique: "湖南省",
                style: style5
            }),
            themeUniqueIteme20 = new SuperMap.REST.ThemeUniqueItem({
                unique: "河南省",
                style: style4
            }),
            themeUniqueIteme21 = new SuperMap.REST.ThemeUniqueItem({
                unique: "河北省",
                style: style3
            }),
            themeUniqueIteme22 = new SuperMap.REST.ThemeUniqueItem({
                unique: "福建省",
                style: style5
            }),
            themeUniqueIteme23 = new SuperMap.REST.ThemeUniqueItem({
                unique: "广西壮族自治区",
                style: style6
            }),
            themeUniqueIteme24 = new SuperMap.REST.ThemeUniqueItem({
                unique: "西藏自治区",
                style: style2
            }),
            themeUniqueIteme25 = new SuperMap.REST.ThemeUniqueItem({
                unique: "广东省",
                style: style4
            }),
            themeUniqueIteme26 = new SuperMap.REST.ThemeUniqueItem({
                unique: "山西省",
                style: style2
            }),
            themeUniqueIteme27 = new SuperMap.REST.ThemeUniqueItem({
                unique: "陕西省",
                style: style1
            }),
            themeUniqueIteme28 = new SuperMap.REST.ThemeUniqueItem({
                unique: "天津市",
                style: style5
            }),
            themeUniqueIteme29 = new SuperMap.REST.ThemeUniqueItem({
                unique: "北京市",
                style: style2
            }),

            themeUniqueIteme30 = new SuperMap.REST.ThemeUniqueItem({
                unique: "辽宁省",
                style: style1
            });

        var themeUniqueItemes = [themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3, themeUniqueIteme4, themeUniqueIteme5, themeUniqueIteme6, themeUniqueIteme7, themeUniqueIteme8, themeUniqueIteme9, themeUniqueIteme10, themeUniqueIteme11, themeUniqueIteme12, themeUniqueIteme13, themeUniqueIteme14, themeUniqueIteme15, themeUniqueIteme16, themeUniqueIteme17, themeUniqueIteme18, themeUniqueIteme19, themeUniqueIteme20, themeUniqueIteme21, themeUniqueIteme22, themeUniqueIteme23, themeUniqueIteme24, themeUniqueIteme25, themeUniqueIteme26, themeUniqueIteme27, themeUniqueIteme28, themeUniqueIteme29, themeUniqueIteme30];

        var themeUnique = new SuperMap.REST.ThemeUnique({
            uniqueExpression: "Name",
            items: themeUniqueItemes,
            defaultStyle: style1
        });
        themeParameters = new SuperMap.REST.ThemeParameters({
            datasetNames: ["China_Province_pg"],
            dataSourceNames: ["China"],
            themes: [themeUnique],
            types: ['REGION']
        });

        themeService.processAsync(themeParameters);
    }

    function themeCompleted(themeEventArgs) {
        if (themeEventArgs.result.resourceInfo.id) {
            themeLayer = new SuperMap.Layer.TiledDynamicRESTLayer("中国行政区划_专题图", url, {
                cacheEnabled: false,
                transparent: true,
                layersID: themeEventArgs.result.resourceInfo.id
            }, {"maxResolution": "auto"});
            themeLayer.events.on({"layerInitialized": addThemeLayer});
        }
    }
    function addThemeLayer() {
        map.addLayer(themeLayer);
    }

    function themeFailed(serviceFailedEventArgs) {
        //doMapAlert("",serviceFailedEventArgs.error.errorMsg,true);
        widgets.alert.showAlert(serviceFailedEventArgs.error.errorMsg,false);
    }

    function removeTheme() {
        if (map.layers.length > 1) {
            map.removeLayer(themeLayer, true);
        }
    }

</script>
</body>
</html>
